﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="POS.test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script language="javascript" src="/Scripts/LodopFuncs.js"></script>
    <object id="LODOP_OB" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0> 
	<embed id="LODOP_EM" type="application/x-print-lodop" width=0 height=0 pluginspage="install_lodop32.exe"></embed>
    <object id="LODOP_OB1" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0> 
	<embed id="LODOP_EM1" type="application/x-print-lodop" width=0 height=0 pluginspage="install_lodop32.exe"></embed>
</object> 
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <p>
            <a href="javascript:printPreview()">print preview</a>
            <a href="javascript:printOrder()">print directly</a>    
            <asp:Button ID = "printButton" Text = "print!" runat = "server" OnClick = "btn_print_click"/>
        </p>
    </div>
    </form>
<script language="javascript" type="text/javascript">
    var LODOP; //声明为全局变量  
    var LODOP1; //声明为全局变量  
    function printPreview() {
        //创建小票打印页  
        CreateOneFormPage1();
        //打印预览  
        LODOP1.PREVIEW();
    };
    /**  
    * 样例函数,服务器确认订单后执行  
    */
    function printOrder() {

        //创建小票打印页  
        CreateOneFormPage();
        CreateOneFormPage1();
        //开始打印
//        LODOP.PRINT();
        LODOP1.PRINT();

    };

    function CreateOneFormPage() {
        LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
        LODOP.PRINT_INIT("打印控件功能演示_Lodop功能_表单一");
        LODOP.SET_PRINT_PAGESIZE();
        LODOP.SET_PRINTER_INDEX(-1);
        LODOP.SET_PRINT_STYLE("FontSize", 18);
        LODOP.ADD_PRINT_TEXT(50, 331, 260, 39, "Receipt");
        LODOP.ADD_PRINT_LINE(100, 100, 100, 600, 0, 1);
        LODOP.ADD_PRINT_TEXT(150, 231, 260, 39, "sushi");
        LODOP.ADD_PRINT_TEXT(150, 431, 260, 39, "3.5");
        LODOP.ADD_PRINT_TEXT(200, 231, 260, 39, "fish");
        LODOP.ADD_PRINT_TEXT(200, 431, 260, 39, "4.6");
        LODOP.ADD_PRINT_LINE(600, 100, 600, 600, 0, 1);
    };

    function CreateOneFormPage1() {
        LODOP1 = getLodop(document.getElementById('LODOP_OB1'), document.getElementById('LODOP_EM1'));
        LODOP1.PRINT_INIT("打印控件功能演示_Lodop功能_表单一");
        LODOP.SET_PRINT_PAGESIZE(3, "302px", "100px", "");
        LODOP1.SET_PRINTER_INDEX(4);
        LODOP1.SET_PRINT_STYLE("FontSize", 18);
        LODOP1.ADD_PRINT_TEXT("1cm", "1cm", "2cm", "50mm", "zql");
        LODOP1.ADD_PRINT_LINE("2cm", "50mm", "2cm", "5cm", 0, 1);
        LODOP1.ADD_PRINT_TEXT(150, 231, 260, 39, "sushi");
        LODOP1.ADD_PRINT_TEXT(150, 431, 260, 39, "3.5");
        LODOP1.ADD_PRINT_TEXT(200, 231, 260, 39, "fish");
        LODOP1.ADD_PRINT_TEXT(200, 431, 260, 39, "4.6");
        LODOP1.ADD_PRINT_LINE(600, 100, 600, 600, 0, 1);
    };

    function CreatePrintPage(json) {
        //json 创建模拟服务器响应的订单信息对象
        alert("faf");  
        var json = { "title": "XXXXX订单信息", "name": "张三", "phone": "138123456789", "orderTime": "2012-10-11 15:30:15",
            "orderNo": "20122157481315", "shop": "XX连锁", "total": 25.10, "totalCount": 6,
            "goodsList": [
        { "name": "菜心(无公害食品)", "price": 5.00, "count": 2, "total": 10.08 },
        { "name": "菜心(无公害食品)", "price": 5.00, "count": 2, "total": 10.02 },
        { "name": "旺菜", "price": 4.50, "count": 1, "total": 4.50 },
        { "name": "黄心番薯(有机食品)", "price": 4.50, "count": 1, "total": 4.50 }
        ]
        }
        
        var hPos = 10, //小票上边距  
        pageWidth = 580, //小票宽度  
        rowHeight = 15, //小票行距  
        //获取控件对象  
        LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
        //初始化   
        LODOP.PRINT_INIT("打印控件功能演示_Lodop功能_名片");
        //添加小票标题文本  
        LODOP.SET_PRINT_STYLE("FontSize", 18);
        LODOP.SET_PRINT_STYLE("Bold", 1);
        LODOP.ADD_PRINT_TEXT(hPos, 30, pageWidth, rowHeight, json.title);
        //上边距往下移  
        hPos += rowHeight;
        
        LODOP.ADD_PRINT_TEXT(hPos, 1, pageWidth, rowHeight, "姓名:");
        LODOP.ADD_PRINT_TEXT(hPos, 30, pageWidth, rowHeight, json.name);
        //hPos+=rowHeight; //电话不换行  
        LODOP.ADD_PRINT_TEXT(hPos, 70, pageWidth, rowHeight, "电话:");
        LODOP.ADD_PRINT_TEXT(hPos, 100, pageWidth, rowHeight, json.phone);
        hPos += rowHeight;
        LODOP.ADD_PRINT_TEXT(hPos, 1, pageWidth, rowHeight, "下单时间:");
        LODOP.ADD_PRINT_TEXT(hPos, 60, pageWidth, rowHeight, json.orderTime);
        hPos += rowHeight;
        LODOP.ADD_PRINT_TEXT(hPos, 1, pageWidth, rowHeight, "订单编号:");
        LODOP.ADD_PRINT_TEXT(hPos, 60, pageWidth, rowHeight, json.orderNo);
        hPos += rowHeight;
        LODOP.ADD_PRINT_TEXT(hPos, 1, pageWidth, rowHeight, "取货门店:");
        LODOP.ADD_PRINT_TEXT(hPos, 60, pageWidth, rowHeight, json.shop);
        hPos += rowHeight;
        LODOP.ADD_PRINT_LINE(hPos, 2, hPos, pageWidth, 2, 1);
        hPos += 5;
        LODOP.ADD_PRINT_TEXT(hPos, 1, pageWidth, rowHeight, "商品名称");
        LODOP.ADD_PRINT_TEXT(hPos, 70, pageWidth, rowHeight, "单价");
        LODOP.ADD_PRINT_TEXT(hPos, 110, pageWidth, rowHeight, "数量");
        LODOP.ADD_PRINT_TEXT(hPos, 140, pageWidth, rowHeight, "小计");
        hPos += rowHeight;
        
        //遍历json的商品数组  
        for (var i = 0; i < json.goodsList.length; i++) {

            if (json.goodsList[i].name.length < 4) {
                LODOP.ADD_PRINT_TEXT(hPos, 1, pageWidth, rowHeight, json.goodsList[i].name);
            } else {
                //商品名字过长,其他字段需要换行  
                LODOP.ADD_PRINT_TEXT(hPos, 1, pageWidth, rowHeight, json.goodsList[i].name);
                hPos += rowHeight;
            }
            LODOP.ADD_PRINT_TEXT(hPos, 70, pageWidth, rowHeight, json.goodsList[i].price);
            LODOP.ADD_PRINT_TEXT(hPos, 115, pageWidth, rowHeight, json.goodsList[i].count);
            LODOP.ADD_PRINT_TEXT(hPos, 140, pageWidth, rowHeight, json.goodsList[i].total);
            hPos += rowHeight;
        }

        
        //商品遍历打印完毕,空一行  
        hPos += rowHeight;
        //合计  
        LODOP.ADD_PRINT_TEXT(hPos, 80, pageWidth, rowHeight, "合计:" + json.totalCount);
        LODOP.ADD_PRINT_TEXT(hPos, 130, pageWidth, rowHeight, "￥" + json.total);

        hPos += rowHeight;
        LODOP.ADD_PRINT_TEXT(hPos, 2, pageWidth, rowHeight, (new Date()).toLocaleDateString() + " " + (new Date()).toLocaleTimeString())
        hPos += rowHeight;
        LODOP.ADD_PRINT_TEXT(hPos, 25, pageWidth, rowHeight, "谢谢惠顾,欢迎下次光临!");
        //初始化打印页的规格  
        LODOP.SET_PRINT_PAGESIZE(3, pageWidth, 45, "XXXXX订单信息");
        
    };    
</script>  
</body>
</html>
